package logic

import (
	"context"
	"health/model/mysql"

	"health/registerrpc/internal/svc"
	"health/registerrpc/registerrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *registerrpc.ListRequest) (*registerrpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var registers []mysql.Register
	mysql.DB.Debug().Find(&registers)
	var lists []*registerrpc.RegisterList
	for _, m := range registers {
		list := registerrpc.RegisterList{
			Id:     int64(m.ID),
			Doctor: m.Doctor,
			Price:  float32(m.Price),
			Times:  m.Times,
			Types:  m.Types,
		}
		lists = append(lists, &list)
	}

	return &registerrpc.ListResponse{List: lists}, nil
}
